/**
 * create by young (young2f@outlook.com) on 2024/4/23
 */
'use strict';
const path = require('path');

module.exports = appInfo => {
  const config = {};

  /**
   * 文件路径
   * @type {string}
   */
  config.rootPath = path.resolve(__dirname, '../../');
  config.logsPath = path.resolve(__dirname, '../devLogs');
  config.infoPath = path.resolve(__dirname, '../info');
  config.configInfoPath = config.infoPath + '/config';
  config.sysConfigFile = config.infoPath + '/iiot-config.json';
  config.logger = {
    dir: config.logsPath,
    level: 'WARN',
    outputJSON: true

  };
//2 * 1024 * 1024 * 1024
  config.customLogger = {
    scheduleLogger: {
      consoleLevel: 'NONE',
      file: config.logsPath + '/egg-schedule.log',
    },
  };

  // config.schedule = {
  //   directory: [],
  // };

  /**
   * mongo
   */
   const mongoUrl = '127.0.0.1:22900';
   // const mongoUrl = '127.0.0.1:28080';
  // const mongoUrl = '119.45.189.48:28080';
  // const mongoUrl = 'www.treec.cn:28080';

  const baseUser = 'pmc';
  const dbPwd = 'Afei!168';
  const dbBase = 'pmc';
  const baseUrl = `mongodb://${baseUser}:${dbPwd}@${mongoUrl}/${dbBase}`;
  // const baseUrl = `mongodb://${mongoUrl}/${dbBase}`;

  const busUser = 'pmcBus';
  const dbBus = 'pmcBus';
  const busUrl = `mongodb://${busUser}:${dbPwd}@${mongoUrl}/${dbBus}`;
  // const busUrl = `mongodb://${mongoUrl}/${dbBus}`;

  config.mongoose = {
    clients: {
      pmc: {
        url: baseUrl,
        options: {
          useNewUrlParser: true,useUnifiedTopology: true,
          autoReconnect: true,
          reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
          reconnectInterval: 10000, // Reconnect every 500ms
          useFindAndModify:false
        },
      },
      pmcBus: {
        url: busUrl,
        options: {
          useNewUrlParser: true,useUnifiedTopology: true,
          autoReconnect: true,
          reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
          reconnectInterval: 10000, // Reconnect every 500ms
          useFindAndModify:false
        },
      }
    }
  };

  config.iiotConfig = {
    logger: {
      'level': 'WARN'
    },
    mqtt: {
      enable: true,
      // url: 'tcp://www.iotmqtt.cn',
      // port: 21883,
      url: 'tcp://60.173.17.240',
      port: 10049,
      usr: 'mqtt',
      pwd: 'ztesoft'
    },
    rootPath: '/opt',
    defaultDeviceOnlineSpaceTime: 30
  };
  return config;
};
